<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册 - 智界论坛</title>
    <link rel="stylesheet" href="css/tech-style.css">
</head>
<body>
<div class="main-container">
    <div class="loginBox fade-in-up">
        <div class="header">
            <h2>智界论坛</h2>
            <p>科技交流社区 - 新用户注册</p>
        </div>
        <% String error = (String) request.getAttribute("error"); %>
        <% if (error != null) { %>
            <div class="alert alert-danger" style="background-color: #f8d7da; color: #721c24; padding: 10px; border: 1px solid #f5c6cb; border-radius: 4px; margin-bottom: 15px;">
                <%= error %>
            </div>
        <% } %>
        
        <form method="post" action="register" accept-charset="UTF-8" onsubmit="return validateForm()">
            <div class="item">
                <input type="text" id="username" name="username" required placeholder=" ">
                <label for="username">用户名</label>
            </div>
            <div class="item">
                <input type="email" id="email" name="email" required placeholder=" ">
                <label for="email">电子邮箱</label>
            </div>
            <div class="item">
                <input type="password" id="password" name="password" required placeholder=" ">
                <label for="password">密码</label>
            </div>
            <div class="item">
                <input type="password" id="confirm_password" name="confirm_password" required placeholder=" ">
                <label for="confirm_password">确认密码</label>
            </div>
            <div class="form-group">
                <button type="submit" class="btn btn-primary w-100">注册</button>
            </div>
            <div class="form-group text-center">
                <p>已有账号？<a href="login.jsp">立即登录</a></p>
            </div>
        </form>
    </div>
</div>
<script>
function validateForm() {
    var email = document.getElementById('email').value;
    var emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
    
    if (!emailRegex.test(email)) {
        alert('请输入有效的邮箱地址');
        return false;
    }
    
    var password = document.getElementById('password').value;
    var confirmPassword = document.getElementById('confirm_password').value;
    
    if (password !== confirmPassword) {
        alert('密码不匹配');
        return false;
    }
    
    return true;
}
</script>
</body>
</html>